<?php

class TTimeStamp extends BaseDescriptor
{
	public $autoUpdate = false;
	
	public function __construct($field,$autoUpdate = false,$default = 'CURRENT_TIMESTAMP')
	{
		$this->autoUpdate = $autoUpdate;
		parent::__construct($field,'TIMESTAMP',0,$default);
	}
	
	protected function makeType()
	{
		return $this->type.' ';
	}	

	protected function makeDefault()
	{
		if($this->isNullable && $this->default == null)
			return "default NULL ";
		else if($this->default == null)
			return "";
		else
			if($this->default == 'CURRENT_TIMESTAMP')
				return "default CURRENT_TIMESTAMP ";
			else
				return "default ".$this->makeValue($this->default)." ";
	}	
	
	protected function makeOnUpdate()
	{
		if(!$this->autoUpdate)
			return "";
			
		return " ON UPDATE NOW()";
	}
	
	public function useFieldForStatement($statement)
	{
		return !$this->autoUpdate;
	}	
	
	public function __toString()
	{
		return $this->makeField().$this->makeType().$this->makeNull().$this->makeDefault().$this->makeOnUpdate();
	}		
}

?>